package org.shunfeng.filter;

import org.shunfeng.pojo.SysUser;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter({"/user/changepassword", "/user/topasswordpage", "/user/logout", "/delivery/*"})
public class LoginFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        SysUser sysUser = (SysUser)request.getSession().getAttribute("user");
        if (sysUser != null){
            chain.doFilter(request, response);
        }else {
            response.sendRedirect(request.getContextPath() + "/login.html");
        }
    }
}
